package cn.stylefeng.guns.modular.cb.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbAdvertisement;
import cn.stylefeng.guns.modular.cb.model.params.CbAdvertisementParam;
import cn.stylefeng.guns.modular.cb.model.result.CbAdvertisementResult;
import cn.stylefeng.guns.modular.cb.service.CbAdvertisementService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author ss
 * @Date 2021-01-30 14:48:10
 */
@Controller
@RequestMapping("/cbAdvertisement")
public class CbAdvertisementController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(CbAdvertisementController.class);

    private String PREFIX = "/cb/cbAdvertisement";

    @Autowired
    private CbAdvertisementService cbAdvertisementService;

    /**
     * 跳转到主页面
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/cbAdvertisement.html";
    }

    /**
     * 新增页面
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/cbAdvertisement_add.html";
    }

    /**
     * 编辑页面
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/cbAdvertisement_edit.html";
    }

    /**
     * 新增接口
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CbAdvertisementParam cbAdvertisementParam) {
        this.cbAdvertisementService.add(cbAdvertisementParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CbAdvertisementParam cbAdvertisementParam) {
        this.cbAdvertisementService.update(cbAdvertisementParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CbAdvertisementParam cbAdvertisementParam) {
        this.cbAdvertisementService.delete(cbAdvertisementParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author ss
     * @Date 2021-01-30
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CbAdvertisementParam cbAdvertisementParam) {
        CbAdvertisement detail = this.cbAdvertisementService.getById(cbAdvertisementParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author ss
     * @Date 2021-01-30
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CbAdvertisementParam cbAdvertisementParam) {
        return this.cbAdvertisementService.findPageBySpec(cbAdvertisementParam);
    }

    /**
     * 广告轮播图
     *
     * @author ss
     * @Date 2021-01-30
     */
    @ResponseBody
    @RequestMapping("/list_advertisement")
    public ResponseData listAdvertisement() {
        List<CbAdvertisementResult> list = this.cbAdvertisementService.advertisementList();
        return ResponseData.success(list);
    }
}


